﻿@using Z10Cabbage.Entity;
@using Z10Cabbage.Entity.Helper;
@model Zippy.Data.Collections.PaginatedList<Z10Cabbage.Entity.Z10Order>
@{
    ViewBag.Title = "进货订单列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var db = Zippy.Data.StaticDB.DB;
    var isAdmin = EAP.Logic.Helper.IsAdministrator();
}
<script type="text/javascript" src="/content/scripts/pagemvc.js"></script>
<script type="text/javascript">
		var pageSize = @ViewBag.PageSize;
		var controller = "/Z10InventoryInOrder";
		var sortUrl = "@Html.Raw(Model.ToSortUrl())";
        
		var curChangeBtn;

		$(function () {
			$("#bQuery").click(function () {
				window.location.href = controller + '/Index/?PageSize=' + pageSize 
					+ "&qCreateDateStart=" + encodeURIComponent($("#qCreateDateStart").val())
					+ "&qCreateDateEnd=" + encodeURIComponent($("#qCreateDateEnd").val());			
			});
            
			$("#qCreateDateStart").datepicker({dateFormat:"yy-mm-dd"});
			$("#qCreateDateEnd").datepicker({dateFormat:"yy-mm-dd"});

			$(".xdetail").unbind("click").bind("click",function(){
				var id = $(this).attr("rel");
				parent.go2("/Z10Order/Detail/" + id+ "/?returnUrl=@HttpUtility.UrlEncode(Request.RawUrl)");
			});
		});
</script>
<div style="left: 261px; top: 10px; display: none" id="dSelPanel" class="pop-box w500">
	<h2 rel="title">
		<a title="关闭" class="close" href="javascript:;">关闭</a><span id="selTitle">选择客户</span></h2>
	<div class="con">
		<div class="top">
			<div style="font-size: 20px; font-family: 黑体; font-weight: bold; text-align: left">
				请选择客户</div>
		</div>
		<div class="main" style="height: 500px;">
			<iframe id="ifSel" width="100%" height="100%" frameborder="0"></iframe>
		</div>
	</div>
</div>
<div id="contents">
    <div id="top">
        <div class="con clearfix">
            <div class="fl">
                @Html.Raw(ViewData["TopMenu"].ToString())
            </div>
        </div>
    </div>
    <div id="main">
        @{
            var orCol = Request["orderCol"];
            int iorCol = orCol.ToInt32();
        }
        <table cellspacing="0" cellpadding="0" border="0" rel="main" class="list-table">
            <tr rel="title">
                <th>
                    订单编号
                    @if (iorCol == 1)
                    { 
                        <i title="点击排序" class="icon i_sort i_asc" rel="2"></i>
                    }
                    else if (iorCol == 2)
                    {  
                        <i title="点击排序" class="icon i_sort i_desc" rel="1"></i>
                    }
                    else
                    {  
                        <i title="点击排序" class="icon i_sort i_nosort" rel="1"></i>
                    }
                </th>
                <th>
                    合同额
                </th>
                <th style="width: 100px">
                    运费
                </th>
                <th>
                    应付
                </th>
                <th>
                    已付
                </th>
                <th>
                    客户
                    @if (iorCol == 3)
                    {  
                        <i title="点击排序" class="icon i_sort i_asc" rel="4"></i>
                    }
                    else if (iorCol == 4)
                    {  
                        <i title="点击排序" class="icon i_sort i_desc" rel="3"></i>
                    }
                    else
                    {  
                        <i title="点击排序" class="icon i_sort i_nosort" rel="3"></i>
                    }
                </th>
                <th>
                    下单日期
                    @if (iorCol == 5)
                    {  
                        <i title="点击排序" class="icon i_sort i_asc" rel="6"></i>
                    }
                    else if (iorCol == 6)
                    {  
                        <i title="点击排序" class="icon i_sort i_desc" rel="5"></i>
                    }
                    else
                    {  
                        <i title="点击排序" class="icon i_sort i_nosort" rel="5"></i>
                    }
                </th>
                <th>
                    状态
                </th>
                <th style="width: 140px">
                    操作
                </th>
            </tr>
            @if (Model.Count > 0)
            {
                foreach (var item in Model)
                {
                    var _orderStatus = item.OrderStatus ?? 0;
                    var storedsome = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.InnedSome);
                    var stored = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.Inned);
                    var paidsome = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.PaidSome);
                    var paid = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.Paid);
                    var finished = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.Finished);

                    var items = db.Take<Z10OrderItem>("OrderID=@OrderID", db.CreateParameter("OrderID", item.OrderID ?? 0));
                    string sitems = "";

                    items.ForEach(delegate(Z10OrderItem xitem)
                    {
                        sitems += xitem.Title + " ";
                    });
							   
               
                <tr rel="item">
                    <td>
                        <a href='/Z10Order/Detail/@item.OrderID?ReturnUrl=@HttpUtility.UrlEncode(Request.RawUrl)'>
                            @item.OrderID, @sitems.ToStringChopped(30)</a>
                    </td>
                    <td class="tr">
                        @((item.Total ?? 0).ToString("0.00"))
                    </td>
                    <td class="tr">
                        @((item.FeeShip ?? 0).ToString("0.00"))
                    </td>
                    <td class="tr">
                        @((item.FeeShould ?? 0).ToString("0.00"))
                    </td>
                    <td class="tr">
                        @((item.FeePaid ?? 0).ToString("0.00"))
                    </td>
                    <td>
                        @{                    var customer = item.GetCustomer(db);                    }
                        @if (!_orderStatus.BitIs(EAP.Logic.Z10.OrderStatus.Finished) && isAdmin)
                        { 
                            <input type="button" value="改" class='modiCus' rel="@item.OrderID" />
                        }
                        <span>@(customer == null ? "" : customer.Title)</span>
                    </td>
                    <td>
                        @if (item.DateOrder != null)
                        {
                            <span>@item.DateOrder.Value.ToString("yyyy-MM-dd")</span>
                             
                        }
                    </td>
                    <td>
                        @((typeof(EAP.Logic.Z10.OrderStatus)).ToString(item.OrderStatus ?? 0, typeof(Resources.X)))
                    </td>
                    <td>
                        <a href="javascript:" class="list" id="@("action_" + item.OrderID)">操作</a>
                        <div>
                            <ul class="opt-mmenu" rel="@("action_" + item.OrderID)">
                                <li><i class="icon i_detail"></i><a href="javascript:" rel="@item.OrderID" class="xdetail"
                                    rel="@item.OrderID">详情</a></li>
                                @if (finished == 0)
                                {
                                    if (storedsome == 0 && stored == 0 && paidsome == 0 && paid == 0)
                                    {
                                    <li><i class="icon i_edit"></i><a href="javascript:;" rel="@item.OrderID" class="xedit">
                                        修改</a></li>
                                    <li><i class="icon i_del"></i><a href="javascript:;" rel="@item.OrderID" class="xdel">
                                        删除</a></li>
                                    <li><i class="icon i_terms"></i><a href="javascript:;" rel="@item.OrderID" class="xterms">
                                        附加条款</a></li>
                                    }
                                    if (stored == 0)
                                    {
                                    <li><i class="icon i_putin"></i><a href="javascript:;" rel="@item.OrderID"  class="xputin">
                                        入库</a></li>
                                    }

                                    if (paid == 0)
                                    {
                                    <li><i class="icon i_pay"></i><a href="javascript:;" rel="@item.OrderID"  class="xpay">
                                        付款</a></li> 
                                    }
                                }
                            </ul>
                        </div>
                    </td>
                </tr>
                }
            }
            else
            { 
                <!-- 没有数据的时候显示 -->
                <tr rel="noitem">
                    <td colspan="8" class="msg-box h200">
                        没有任何数据
                    </td>
                </tr>
                <!-- 没有数据的时候显示 -->
            }
        </table>
    </div>
</div>
<div class="pop-box pop-query w600" rel="search" style="z-index: 999">
    <div class="con">
        <a rel="close" class="close mr10" href="javascript:;">关闭</a>
        <div class="msg-box msg-contents">
            <table class="query">
                <tr>
                    <td class='tt'>
                        创建时间：
                    </td>
                    <td>
                        <input type='text' class='text' id='qCreateDateStart' />
                        -
                        <input type='text' class='text' id='qCreateDateEnd' />
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </div>
        <div class="bottom">
            <a class="jenter button" href="javascript:;" id='bShowAll'>显示全部<b></b></a> <a class="jenter button active"
                href="javascript:;" id='bQuery'>查询<b></b></a>
        </div>
    </div>
</div>
<div id="bottom">
    @Html.Raw(Model.ToPagerHtml("Z10StockOrder", "Index", ViewBag.PageSize))
</div>
